package com.itheima.text;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;

public class Test4 {
    public static void main(String[] args) throws IOException {
        //需求：
        //将多个自定义对象序列化到文件中，但是对象的个数不确定，该如何操作呢？
        Student s1 = new Student("张三",23,"南京");
        Student s2 = new Student("李四",26,"北京");
        Student s3 = new Student("王五",25,"重庆");

        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day29-code\\f.txt"));
        oos.writeObject(list);

        oos.close();
    }
}
